package com.symaster.common.connect.v3.core;

/**
 * @author yinmiao
 * @version 2024/1/2
 */
public class ID {
    private static final Object treeLock = new Object();
    private static int idCount = 0;

    private final int id;

    public ID() {
        synchronized (treeLock) {
            this.id = idCount;
            idCount++;
        }
    }

    public ID(int id) {
        this.id = id;
    }

    public int getId() {
        return id;
    }

    @Override
    public String toString() {
        return id + "";
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ID id1 = (ID) o;
        return id == id1.id;
    }

    @Override
    public int hashCode() {
        return id;
    }
}
